package com.pilot.game.repository;

import com.pilot.game.domain.CyclePlan;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


/**
 * Spring Data JPA repository for the CyclePlan entity.
 */
@SuppressWarnings("unused")
@Repository
public interface CyclePlanRepository extends JpaRepository<CyclePlan, Long> {

    /**
     * 查询全部
     *
     * @param kindId   彩种ID
     * @param status   中奖
     * @param pageable 分页
     * @return page
     */
    @Query(value = "SELECT id,彩种ID,子项类型,总期数,起始期数,结束期数,名称,数据,内容,中奖期数,连中,连挂,COUNT(中奖) AS 中奖,日期 " +
        "FROM 每期计划 WHERE 彩种ID = ?1 AND 中奖 = ?2 " +
        "GROUP BY  日期, 名称, 中奖期数 " +
        "order by 日期 DESC /*#pageable*/",
        countQuery = "SELECT COUNT(*) FROM 每期计划 WHERE 彩种ID = ?1 AND 中奖 = ?2 GROUP BY  日期, 名称, 中奖期数",
        nativeQuery = true)
    Page<CyclePlan> findAllWithStatus(int kindId, int status, Pageable pageable);
}

